package cn.tiga._02;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {

     public static void main(String[] args) throws Exception {
         //获取producer对象
         DefaultMQProducer producer = new DefaultMQProducer("xhr-producer-Group");
         //nameserver链接
         producer.setNamesrvAddr("localhost:9876");
         //启动
         producer.start();
         //创建消息对象，设置消息
         Message message = new Message("xhr","hello","我在源码乔达摩".getBytes(StandardCharsets.UTF_8));
         producer.send(message, new SendCallback() {
             @Override
             public void onSuccess(SendResult sendResult) {
                 System.out.println("成功"+sendResult.toString());
             }

             @Override
             public void onException(Throwable throwable) {
                throwable.printStackTrace();
                System.out.println("失白啦");
             }
         });


    }
}
